package MyScanner;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class ScannerTest {
    public static void main(String[] args) throws IOException {
        String srcPath = "F:\\BIT-MiniCC-master\\test\\scan_test\\1_scanner_test_without_annotation.c";
        C_CodeScanner scanner = new C_CodeScanner(srcPath);
        scanner.run();
        String[] tokens = scanner.getTokensArray();
        for(String str : tokens)
        {
            System.out.println(str);
        }

        System.out.println("----------------------------------");

        String[] std = fileReader("F:\\BIT-MiniCC-master\\test\\scan_test\\原版_默认_开预处理.tokens");
        String[] out = fileReader("F:\\BIT-MiniCC-master\\test\\scan_test\\原版_My_开预处理.tokens");

        compareStrArrays(std, out);
    }

    private static String[] fileReader(String fPath) throws IOException
    {
        File file = new File(fPath);
        Scanner sc = new Scanner(file);
        List<String> strList = new ArrayList<>();
        while(sc.hasNext())
        {
            strList.add(sc.nextLine());
        }
        String[] strArray = new String[strList.size()];
        int i = 0;
        for (String str: strList) {
            strArray[i++] = str;
        }
        return strArray;
    }

    private static void compareStrArrays(String[] std, String[] out)
    {
        int l1 = std.length;
        int l2= out.length;
        int minLen = Math.min(l1, l2);
        for(int i = 0; i < minLen; i++)
        {
            if(!std[i].equals(out[i]))
            {
                System.out.println("STD:  " + std[i]);
                System.out.println("OUT:  " + out[i]);
            }
        }
    }
}
